package jp.co.baka.pachinko.service;

import jp.co.baka.pachinko.meta.CounterMstMeta;
import jp.co.baka.pachinko.model.CounterMst;

import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Key;

/**
 * カウンタサービス
 *
 * @author takemura
 *
 */
public class CounterService {


    /**
     * カウンタ名でカウンタのKeyを取得する
     *
     * @param incrementKey
     * @param gtx
     * @return
     */
    public static Key getCounterKey(String counterName){

        Key key = null;
        CounterMstMeta c = CounterMstMeta.get();

        CounterMst counter = Datastore.query(c).filter(c.counterName.equal(counterName)).asSingle();
        if(counter==null){
            CounterMst newRecord = new CounterMst();
            newRecord.setCounterName(counterName);
            newRecord.setCountValue(0L);
            key = Datastore.put(newRecord);

        }else{
            key = counter.getKey();
        }

        return key;
    }




}
